<template>
		<el-button type="primary" size="medium" @click="outexcel()">导出</el-button>
</template>

<script>
	import {export_json_to_excel } from 'common/js/Export2Excel.js'
	export default {
		name:'MyExcel',
		props:{
			outdata:{
				type:Array,
				default:[]
			},
			titlearr:{
				type:Array,
				default:[]
			},
			fieldarr:{
				type:Array,
				default:[]
			},
			filename:{
				type:String,
				default:'excel数据导出表'
			}
		},
		methods:{
			outexcel(){
        require.ensure([], () => {
	        //设置标题..
	        	const tHeader = this.titlearr;
	       	//设置数组关联字段..
	        	const filterVal = this.fieldarr;
	        //数据集..
		        const list = this.outdata;  
		        const data = this.formatJson(filterVal, list);
	        // excel名称可自定义
	        const excelName = this.filename;
	        export_json_to_excel(tHeader, data, excelName);
	      });     
      },
      formatJson(filterVal, jsonData) {
        return jsonData.map(v => filterVal.map(j => v[j]))
      }
		}
	}
</script> 


<style scoped></style>